package com.khyr.service.impl;

import com.alibaba.nacos.common.utils.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.khyr.dao.RegFeeDao;
import com.khyr.entity.RegFee;
import com.khyr.service.RegFeeService;
import com.khyr.vo.R;
import com.khyr.vo.RegFeeVo;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 宋一恒
 * @version 1.0
 */
@Service
public class RegFeeServiceImpl implements RegFeeService {
    @Autowired
    private RegFeeDao regFeeDao;

    @Override
    public R<Page<RegFee>> findRegisteredItemByCond(RegFeeVo regFeeVo) {
        //分页
        Page<RegFee> page = new Page<>(regFeeVo.getPageNum(), regFeeVo.getPageSize());
        //模糊
        QueryWrapper<RegFee> queryWrapper = new QueryWrapper<>();
        if (StringUtils.hasText(regFeeVo.getRegItemName())){
            System.out.println("=========================================================");
            queryWrapper.like("reg_item_name", regFeeVo.getRegItemName());
        }
        if (StringUtils.hasText(regFeeVo.getKeywords())){
            queryWrapper.like("keywords", regFeeVo.getKeywords());
        }
        if (StringUtils.hasText(regFeeVo.getTypeId())){
            queryWrapper.like("type_id", regFeeVo.getTypeId());
        }
        if (StringUtils.hasText(regFeeVo.getStatus())){
            queryWrapper.like("status", regFeeVo.getStatus());
        }
        Page<RegFee> PageInfo = regFeeDao.selectPage(page, queryWrapper);
        if (PageInfo != null){
            return new R<>(200,"查询成功", PageInfo);
        }
        return new R<>(500,"查询失败", null);
    }

    @Override
    public R<String> addRegFee(RegFee regFee) {
        if (regFeeDao.insert(regFee) > 0){
            return new R<>(200,"添加成功", null);
        }
        return new R<>(500,"添加失败", null);
    }

    @Override
    public R<String> updateRegFee(RegFee regFee) {
        if (regFeeDao.updateById(regFee) > 0){
            return new R<>(200,"修改成功", null);
        }
        return new R<>(500,"修改失败", null);
    }

    @Override
    public R<String> deleteRegFeeById(Long id) {
        if (regFeeDao.deleteById(id) > 0){
            return new R<>(200,"删除成功", null);
        }
        return new R<>(500,"删除失败", null);
    }

    @Override
    public R<String> deleteRegFeeByIds(List<Long> ids) {
        if (ids != null){
            int i = regFeeDao.deleteIds(ids);
            if (i > 0){
                return new R<>(200,"删除成功", null);
            }
        }
        return new R<>(500,"删除失败", null);
    }
}
